"use strict";
cc._RF.push(module, '9c104rlkg9CS43h3MFra2/y', 'LogUtil');
// script/standar/utils/LogUtil.ts

"use strict";
var __spreadArrays = (this && this.__spreadArrays) || function () {
    for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;
    for (var r = Array(s), k = 0, i = 0; i < il; i++)
        for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)
            r[k] = a[j];
    return r;
};
Object.defineProperty(exports, "__esModule", { value: true });
var ArrayUtil_1 = require("./ArrayUtil");
/**
 * LogUtil:日志相关接口
 * @author ituuz
 * @description 日志分级、日志打印、日志保存
 */
var LogUtil = /** @class */ (function () {
    function LogUtil() {
    }
    LogUtil.log = function (message) {
        var optionalParams = [];
        for (var _i = 1; _i < arguments.length; _i++) {
            optionalParams[_i - 1] = arguments[_i];
        }
        if (!LogUtil._logStatus) {
            return;
        }
        LogUtil._logStr += "[log][" + LogUtil.getFullTime() + "]" + LogUtil.GLOBAL_TAG + ":"
            + message + ArrayUtil_1.default.stringify(optionalParams) + "\n";
        // tslint:disable-next-line: no-console
        console.log.apply(console, __spreadArrays(["[log][", LogUtil.getFullTime(), "]", LogUtil.GLOBAL_TAG, ":", message], optionalParams));
    };
    LogUtil.debug = function (message) {
        var optionalParams = [];
        for (var _i = 1; _i < arguments.length; _i++) {
            optionalParams[_i - 1] = arguments[_i];
        }
        if (!LogUtil._logStatus) {
            return;
        }
        LogUtil._logStr += "[debug][" + LogUtil.getFullTime() + "]" + LogUtil.GLOBAL_TAG + ":"
            + message + ArrayUtil_1.default.stringify(optionalParams) + "\n";
        // tslint:disable-next-line: no-console
        console.debug.apply(console, __spreadArrays(["[debug][", LogUtil.getFullTime(), "]", LogUtil.GLOBAL_TAG, ":", message], optionalParams));
    };
    LogUtil.warn = function (message) {
        var optionalParams = [];
        for (var _i = 1; _i < arguments.length; _i++) {
            optionalParams[_i - 1] = arguments[_i];
        }
        if (!LogUtil._logStatus) {
            return;
        }
        LogUtil._logStr += "[warn][" + LogUtil.getFullTime() + "]" + LogUtil.GLOBAL_TAG + ":"
            + message + ArrayUtil_1.default.stringify(optionalParams) + "\n";
        // tslint:disable-next-line: no-console
        console.warn.apply(console, __spreadArrays(["[warn][", LogUtil.getFullTime(), "]", LogUtil.GLOBAL_TAG, ":", message], optionalParams));
    };
    LogUtil.error = function (message) {
        var optionalParams = [];
        for (var _i = 1; _i < arguments.length; _i++) {
            optionalParams[_i - 1] = arguments[_i];
        }
        if (!LogUtil._logStatus) {
            return;
        }
        LogUtil._logStr += "[error][" + LogUtil.getFullTime() + "]" + LogUtil.GLOBAL_TAG + ":"
            + message + ArrayUtil_1.default.stringify(optionalParams) + "\n";
        // tslint:disable-next-line: no-console
        console.error.apply(console, __spreadArrays(["[error][", LogUtil.getFullTime(), "]", LogUtil.GLOBAL_TAG, ":", message], optionalParams));
    };
    /** 写入文件保存 */
    LogUtil.save = function (cb) {
        if (cc.sys.isNative) {
            var path = jsb.fileUtils.getWritablePath() + "log/" + LogUtil.getFileName();
            // @ts-ignore
            jsb.fileUtils.writeDataToFile(LogUtil._logStr, path);
            LogUtil.log("日志保存成功:", path);
            LogUtil._logStr = "";
            if (cb) {
                cb();
            }
        }
    };
    /** 获取完全时间 */
    LogUtil.getFullTime = function () {
        var date = new Date();
        return date.getHours() + ":" + date.getMinutes() + ":" + date.getSeconds() + "-" + date.getMilliseconds();
    };
    /** 获取文件名 */
    LogUtil.getFileName = function () {
        var date = new Date();
        return date.getMonth() + "-" + date.getDay() + "_" + date.getHours() + ":" +
            date.getMinutes() + ":" + date.getSeconds() + ".log";
    };
    /** 设置日志状态 */
    LogUtil.setLogStatus = function (flag) {
        LogUtil._logStatus = flag;
        if (flag) {
            // 定时保存日志
            // setInterval(() => {
            //     LogUtil.save();
            // }, 1000 * 15);
        }
    };
    /** log标签 */
    LogUtil.GLOBAL_TAG = "LOG_TAG";
    /** log 日志信息 */
    LogUtil._logStr = "";
    /** log状态 */
    LogUtil._logStatus = true;
    return LogUtil;
}());
exports.default = LogUtil;

cc._RF.pop();